<template>
	<view class="wf-box">
		<view class="head" :style="{ paddingTop: navBarHeight }">
			<view class="head-np">
				<view class="back" @click="back()">
					<image src="../../static/img/me-43.png"></image>
				</view>
				<view class="title">兑换</view>
				<image @click="record()" class="record" src="@/static/img/record.png"></image>
			</view>
		</view>

		<view class="main" :style="{ paddingTop: navBarHeight }">
			<view class="title">主网 <text>{{info.text}}</text></view>
			<image class="er" :src="qrCodeBase64" mode="aspectFit" />
			<div ref="qrcode"></div>
			<view class="number">{{info.address}}</view>
			<view class="hint">仅支持对该地址BNB Smart Chain({{info.text}})网络兑换KT</view>
			<view class="copy" @click="copy(info.address)">
				<image src="@/static/img/copy.png" mode="widthFix"></image>
				<view>复制地址</view>
			</view>
		</view>
		<view class="notice">
			注意：此币种最低兑换数量为1，请不要兑换低于该数量否则可能会无法到账。<br>请勿向上述地址兑换非{{info.text}}资产，否则资产将不可找回。
		</view>
	</view>
</template>

<script>
	import navBarMixin from '@/mixin/navBarMixin.js'
	// import QRCode from 'qrcode'
	export default {
		data() {
			return {
				qrCodeBase64: '',
				info: '',
			}
		},
		mixins: [navBarMixin],
		methods: {
			copy(e) {
				uni.setClipboardData({
					data: e,
					showToast: false,
					success: function() {
						uni.showToast({
							title: '复制成功',
							icon: 'none',
							duration: 2000
						})
					}
				})
			},
			back() {
				uni.navigateBack()
			},
			record() {
				uni.navigateTo({
					url: '/pages/me/rechargeRecord'
				})
			},
			async createQRCode(text) {
				try {
					// 生成二维码
					this.qrCodeBase64 = await QRCode.toDataURL(text);
				} catch (error) {
					console.error('生成二维码失败:', error);
				}
			}

		},
		onLoad(e) {
			this.info = JSON.parse(e.info)
			this.createQRCode(this.info.address)
		},
		mounted() {
			// 生成二维码

		},
	}
</script>

<style lang="scss" scoped>
	.wf-box {
		position: relative;
		overflow: hidden;
		height: 100vh;
		background: #3F93FF;
		background-size: 100% 100%;
	}

	.head {
		position: fixed;
		z-index: 1;
		width: 100%;
		background: transparent;

		.head-np {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 100%;
			height: 96rpx;
			padding: 0 30rpx;
			box-sizing: border-box;

			.back {
				image {
					width: 20rpx;
					height: 37rpx;
				}
			}

			.title {
				font-size: 36rpx;
				font-weight: bold;
				color: #fff;
			}

			.record {
				width: 50rpx;
				height: 50rpx;
			}
		}
	}

	.main {
		margin: 0 40rpx;
		margin-top: 176rpx;
		overflow: hidden;
		height: 856rpx;
		background: #FFFFFF;
		border-radius: 22rpx;
		text-align: center;

		image {
			display: block;
		}

		.title {
			font-size: 30rpx;
			margin-top: 40rpx;

			text {
				font-weight: 500;
			}
		}

		.er {
			width: 375rpx;
			height: 375rpx;
			margin: 40rpx auto;
		}

		.number {
			font-size: 26rpx;
			color: #999999;
			line-height: 42rpx;
		}

		.hint {
			font-size: 30rpx;
			margin: 30rpx 150rpx;
			line-height: 42rpx;
		}

		.copy {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #3F93FF;
			font-size: 30rpx;

			image {
				width: 50rpx;
				margin-right: 20rpx;
			}
		}
	}

	.notice {
		margin: 40rpx;
		font-size: 26rpx;
		color: #EEEEEE;
		line-height: 42rpx;
	}
</style>